import api from './userService';
import { PostListParams, PostListResponse } from '../../types/post';

/**
 * 分页获取首页帖子列表
 * @param params 分页参数
 */
export const getHomePosts = async (params: PostListParams) => {
  const res = await api.post('/api/post/list/page/vo', params);
  return res;
};

/**
 * 获取帖子详情
 * @param postId 帖子ID
 */
export const getPostDetail = async (postId: number) => {
  const res = await api.get(`/api/post/get/detail?id=${postId}`);
  return res;
};

/**
 * 点赞/取消点赞帖子
 * @param postId 帖子ID
 */
export const toggleLikePost = (postId: number) => {
  return api.post('/api/post_thumb/', { postId });
};

/**
 * 收藏/取消收藏帖子
 * @param postId 帖子ID
 */
export const toggleFavoritePost = (postId: number) => {
  return api.post('/api/post_favour/', { postId });
};

/**
 * 创建帖子
 * @param postData 帖子数据
 */
export const createPost = (postData: {
  title: string;
  content: string;
  tags?: string[];
  summary?: string;
  images?: string[];
}) => {
  return api.post('/api/post/add', postData);
};

/**
 * 带图片创建帖子（一体式上传）
 * @param formData 包含帖子内容和图片文件的FormData
 */
export const createPostWithImages = (formData: FormData) => {
  return api.post('/api/post/add/with-images', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

// Expo Router 要求每个可路由文件导出一个默认的React组件，这里导出一个空组件用于消除警告
export default function PostServiceComponent() {
  return null;
} 